﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Texfina.Core.Web;
using Texfina.BOQry.Co;
using Texfina.Core.Common;
using Texfina.Entity.Co;

namespace CO
{
    public partial class wfImportacionMnt : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsCallback) return;

            if (!Page.IsPostBack)
            {
                LoadData();
                ListarImportaciones();
            }
        }
        public void RefreshLoadNumbers()
        {
            AddCallbackControl(dpEmbarque);
            AddCallbackControl(dpTipTerminos);
        }

        private void LoadData()
        {
            btnNuevo.ImageUrl = Constants2.ConstMenuControlValue.BUTTON_NEW;
            btnGrabar.ImageUrl = Constants2.ConstMenuControlValue.BUTTON_SAVENEW;
            btnSalir.ImageUrl = Constants2.ConstMenuControlValue.BUTTON_EXIT;
            WebHelper.LoadListControl2(dpTipTerminos, BTablaGeneral.TablaGeneralFill("135"), "ds_item", "id_item");
            WebHelper.LoadListControl2(dpEmbarque, BTablaGeneral.TablaGeneralFill("134"), "ds_item", "id_item");
        }

        //protected void mnuToolbar_MenuItemClick(object sender, MenuEventArgs e)
        //{
        //    if (e.Item == null)
        //        return;

        //    switch (e.Item.Value)
        //    {
        //        case Constants.ConstMenuToolbarValue.BUTTON_SAVE:
        //            EImportacion prov = new EImportacion();

        //            DropDownList idImp = new DropDownList();
        //            if (txtCodigo.Text == "")
        //            {
        //                WebHelper.LoadListControl(idImp,BImportacion.Importacion_qry01(), "id_Importacion", "id_Importacion");
        //                hddIdimportacion.Value = idImp.SelectedItem.Text;
        //                prov.Id_importa = hddIdimportacion.Value;

        //            }
        //            else
        //            {
        //                prov.Id_importa = txtCodigo.Text;
        //            }
        //            prov.Ds_importa = txtDescrip.Text;
        //            prov.Id_via = dpEmbarque.SelectedValue;
        //            prov.Id_tercom = dpTipTerminos.SelectedValue;
        //            prov.Id_ucrearec = "vsoto";
        //            prov.Id_uupdarec = "vsoto";
        //            BImportacion.Importacion_mnt01(prov);
        //            lblMensaje.Text = "Datos Grabados";

        //            break;
        //        case Constants.ConstMenuToolbarValue.BUTTON_SAVENEW:


        //        case Constants.ConstMenuToolbarValue.BUTTON_EXIT:
        //            this.Response.Redirect("WfProveedorBnd.aspx");
        //            break;
        //    }

        //}

        protected void btnBuscar_Click(object sender, ImageClickEventArgs e)
        {
            //this.mdlPopup.Show();
        }
        private void ListarImportaciones()
        {
            //try
            //{
            //    EImportacion imp = new EImportacion();

            //    imp.Id_importa = txtCodigo.Text;

            //    imp.Ds_importa = txtDes.Text;

            //    gvListar.DataSource = BImportacion.GetListFill(imp);

            //    gvListar.DataBind();
            //}
            //catch (Exception ex)
            //{
            //    Response.Write(ex.ToString());
            //}
        }
        protected void cmdbuscar_Click(object sender, EventArgs e)
        {
            ListarImportaciones();
        }

        protected void btnBuscar_Click1(object sender, EventArgs e)
        {
            try
            {
                Session[Constants2.ConstSessionVar.SESION_IMPORTACION] = "__SESION_IMPORTACION";
                ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( 'wfImportacionesBnd.aspx', null, 'height=400,width=700,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' );", true);

            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }

        protected void btnGrabar_Click(object sender, ImageClickEventArgs e)
        {
            EImportacion prov = new EImportacion();

            DropDownList idImp = new DropDownList();
            if (txtCodigo.Text == "")
            {
                WebHelper.LoadListControl2(idImp, BImportacion.Importacion_qry01(), "id_Importacion", "id_Importacion");
                hddIdimportacion.Value = idImp.SelectedItem.Text;
                prov.Id_importa = hddIdimportacion.Value;

            }
            else
            {
                prov.Id_importa = txtCodigo.Text;
            }
            prov.Ds_importa = txtDescrip.Text;
            prov.Id_via = dpEmbarque.SelectedValue;
            prov.Id_tercom = dpTipTerminos.SelectedValue;
            prov.Id_ucrearec = "vsoto";
            prov.Id_uupdarec = "vsoto";
            BImportacion.Importacion_mnt01(prov);
            lblMensaje.Text = "Datos Grabados";

        }

        protected void btnNuevo_Click(object sender, ImageClickEventArgs e)
        {
            txtCodigo.Text = "";
            txtDescrip.Text = "";

        }


    }
}